package com.ruoyi.web.controller.module;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.module.splitAccount.SplitAccountRecord;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.module.splitAccount.ISplitAccountRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 账户 动账记录Controller
 *
 * @author ruoyi
 * @date 2022-05-14
 */
@Validated
@Api(value = "账户 动账记录控制器", tags = {"账户 动账记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/split/account/record")
public class SplitAccountRecordController extends BaseController {

    private final ISplitAccountRecordService splitAccountRecordService;

    /**
     * 查询账户 动账记录列表
     */
    @ApiOperation("查询账户 动账记录列表")
    @PreAuthorize("@ss.hasPermi('module:accountRecord:list')")
    @GetMapping("/list")
    public TableDataInfo<SplitAccountRecord> list(@Validated SplitAccountRecord splitAccountRecord) {
        QueryWrapper<SplitAccountRecord> qw = new QueryWrapper<>();

        TableDataInfo<SplitAccountRecord> td = PageUtils.buildDataInfo(splitAccountRecordService.page(PageUtils.buildPage(),qw));
        List<SplitAccountRecord> list = td.getRows();
        return td;
    }

    /**
     * 导出账户 动账记录列表
     */
    @ApiOperation("导出账户 动账记录列表")
    @PreAuthorize("@ss.hasPermi('module:accountRecord:export')")
    @Log(title = "账户 动账记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SplitAccountRecord> export(@Validated SplitAccountRecord splitAccountRecord) {
        List<SplitAccountRecord> list = splitAccountRecordService.list();
        ExcelUtil<SplitAccountRecord> util = new ExcelUtil<SplitAccountRecord>(SplitAccountRecord.class);
        return util.exportExcel(list, "账户 动账记录");
    }

    /**
     * 获取账户 动账记录详细信息
     */
    @ApiOperation("获取账户 动账记录详细信息")
    @PreAuthorize("@ss.hasPermi('module:accountRecord:query')")
    @GetMapping("/{id}")
    public AjaxResult<SplitAccountRecord> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        SplitAccountRecord splitAccountRecord = splitAccountRecordService.getById(id);
        return AjaxResult.success(splitAccountRecord);
    }

    /**
     * 新增账户 动账记录
     */
    @ApiOperation("新增账户 动账记录")
    @PreAuthorize("@ss.hasPermi('module:accountRecord:add')")
    @Log(title = "账户 动账记录", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody SplitAccountRecord splitAccountRecord) {
        return toAjax(splitAccountRecordService.save(splitAccountRecord) ? 1 : 0);
    }

    /**
     * 修改账户 动账记录
     */
    @ApiOperation("修改账户 动账记录")
    @PreAuthorize("@ss.hasPermi('module:accountRecord:edit')")
    @Log(title = "账户 动账记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody SplitAccountRecord splitAccountRecord) {
        return toAjax(splitAccountRecordService.updateById(splitAccountRecord) ? 1 : 0);
    }

    /**
     * 删除账户 动账记录
     */
    @ApiOperation("删除账户 动账记录")
    @PreAuthorize("@ss.hasPermi('module:accountRecord:remove')")
    @Log(title = "账户 动账记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Long[] ids) {
        return toAjax(splitAccountRecordService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
